package com.link2room.aeriabots.service.impl;

import com.link2room.aeriabots.service.IWxComponentService;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.dao.ICommonDao;
import com.link2room.common.exception.SysException;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.common.util.StringUtil;
import com.link2room.aeriabots.entity.WxComponent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2016/9/1.
 */
@Component("wxComponentService")
public class WxComponentServiceImpl implements IWxComponentService {
    @Resource
    private ICommonDao commonDao;
    @Override
    public WxComponent findByItem(String lhotelGroupCode, String lhotelCode, String item) throws Exception {
        WxComponent wxComponent = new WxComponent();
        if(StringUtil.isBlank(item)){
            throw new SysException(BaseSysExceptionEnum.INVALID_PARA.getCode(), BaseSysExceptionEnum.INVALID_PARA.getMsg()+"item IS NULL", BaseSysExceptionEnum.INVALID_PARA.getBizType());
        }
        wxComponent.setItem(item);
        if(StringUtil.isNotBlank(lhotelGroupCode)){
            wxComponent.setLhotelGroupCode(lhotelGroupCode);
        }
        if(StringUtil.isNotBlank(lhotelCode)){
            wxComponent.setLhotelCode(lhotelCode);
        }
        return  commonDao.findOne(WxComponent.class, CriteriaUtil.getCriteriaAllEQ(wxComponent));
    }
}
